package com.example.edz.splashdemo;

import android.os.Build;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ScreenUtil.transparencyBar(this);
        TextView textView = findViewById(R.id.tv_count_down);
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) textView.getLayoutParams();
        layoutParams.topMargin += ScreenUtil.getStatusBarHeight(this);
        textView.setLayoutParams(layoutParams);
        //全面屏不支持去除状态栏 则退出全屏幕 采用更改状态栏为透明色的方法
        if(isCongainer(android.os.Build.BRAND,getResources().getStringArray(R.array.exit_fullscreen))&&ScreenUtil.getScreentRation(this)>1.86){
            exitFullScreen();
        }
    }
    /**
     * 退出全面屏手机模式
     */
    private void exitFullScreen(){
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            WindowManager.LayoutParams attributes = window.getAttributes();
            attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
            window.setAttributes(attributes);
        }
    }
    private boolean isCongainer(String str,String[] datas){
        for (String s:datas){
            if (TextUtils.equals(str,s)){
                return true;
            }
        }
        return false;
    }
}

